<template>
  
  <el-dialog :title="props.title" v-model="pd.open" width="900px" append-to-body 
             :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-row>
      <el-table v-loading="pd.loading" highlight-current-row @select="select1" @row-click="clickRow" ref="refTable"
                :data="pd.accountLogList" @selection-change="handleSelectionChange" height="260px">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="主键" align="center" prop="id"/>
        <el-table-column label="名称" align="center" prop="accountNo"/>
        <el-table-column label="当前余额" align="center" prop="currentAmount"/>
        <el-table-column label="最终余额" align="center" prop="finalAmount"/>
        <el-table-column label="备注" align="center" prop="remark"/>
        <el-table-column label="删除标记" align="center" prop="delFlag"/>
        <el-table-column label="租户" align="center" prop="tenantId"/>
        <el-table-column label="创建时间" align="center" prop="createTime"/>
        <el-table-column label="创建者" align="center" prop="createBy"/>
      </el-table>
      <pagination v-show="pd.total > 0" :total="pd.total" v-model:page="pd.queryParams.pageNum"
                  v-model:limit="pd.queryParams.pageSize" @pagination="getAccountLogById"/>
    </el-row>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="close" type="warning">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup name="accountLogSearch">
import {getCurrentInstance, reactive} from "vue";
import {getAccountLog} from '@/api/fms/accountLog'
const {proxy} = getCurrentInstance();

const props = defineProps({
  // 字典名称
  
  title: {
    type: String,
    default: "流水日志"
  },
  // 是否单选
  isSingle: {
    type: Boolean,
    default: true
  },
  isButton: {
    type: Boolean,
    default: false
  },
});

let pd = reactive({
  accountLogList: [
    {id:null}
  ],
  open: false,
  loading: true,
  total: 0,
  inputText: "",
  reParams: [],
  queryParams: {
    id:"",
    pageNum: 1,
    pageSize: 10,
  }
})

// 显示弹框
function show(id) {
  getAccountLogById(id)
  pd.open = true;
}

function select1(selection,row){
  if (props.isSingle) {
    proxy.$refs["refTable"].clearSelection();
  }
  proxy.$refs["refTable"].toggleRowSelection(row,true);
}

//关闭流水日志页面时重置accountLogList
function close(){
  pd.open=false
  pd.accountLogList=[
    {id:null}
  ]
}
// 查询表数据
function getAccountLogById(id) {
  pd.loading = true;
  if (pd.accountLogList[0].id===null){
    pd.queryParams.id=id
  }else {
    pd.queryParams.id=pd.accountLogList[0].id
  }
  getAccountLog(pd.queryParams).then(res => {
    pd.accountLogList = res.data;
    pd.total = res.total;
    pd.loading = false;
  });
}


defineExpose({
  show,
});

</script>